package com.onesports.intelligent.k12.polarlight.config;

import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.cors.CorsConfiguration;

/**
 * @author aj
 */
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

    private final Security security = new Security();

    private final Wx wx = new Wx();
    @Getter
    private final Redis redis = new Redis();

    @Getter
    private final CorsConfiguration cors = new CorsConfiguration();

    @Getter
    private final Captcha captcha = new Captcha();

    @Getter
    private final WxPay wxPay = new WxPay();

    public Wx getWx() {
        return this.wx;
    }

    public Security getSecurity() {
        return security;
    }

    @Data
    public static class Security {
        private String contentSecurityPolicy = "default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com https://api.map.baidu.com; style-src 'self' 'unsafe-inline'; img-src *; font-src 'self' data:";

        private final Authentication authentication = new Authentication();

        @Data
        public static class Authentication {
            private final Client client = new Client();

            private long tokenValidityInSeconds;
            @Data
            public static class Client {
                private long tokenValidityInSeconds;

                private String resourceIds;
            }
        }
    }

    public static class Redis {
        private String password;

        private int db;

        private final Redis.Cache cache = new Redis.Cache();

        private final Redis.SecondLevelCache secondLevelCache = new Redis.SecondLevelCache();

        private final Redis.Lock lock = new Redis.Lock();

        public Cache getCache() {
            return cache;
        }

        public SecondLevelCache getSecondLevelCache() {
            return secondLevelCache;
        }

        public Lock getLock() {
            return lock;
        }

        @Data
        public static class Cache {

            private long expiration;
        }

        @Data
        public static class SecondLevelCache {

            private long expiration;
        }

        @Data
        public static class Lock {
            /**
             * 分布式锁-看门狗超时时间
             */
            private long lockWatchdogTimeout;
        }

        public int getDb() {
            return db;
        }

        public void setDb(int db) {
            this.db = db;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }

    public static class Wx {

        private final Miniapp miniapp = new Miniapp();

        private final MessageTemplate messageTemplate = new MessageTemplate();

        public Wx() {
        }

        public Miniapp getMiniapp() {
            return this.miniapp;
        }

        public MessageTemplate getMessageTemplate() {
            return this.messageTemplate;
        }

        @Data
        public static class Miniapp {

            private String appid;

            private String secret;

            private String mpAppid;

            private String envVersion;

        }

        @Data
        public static class MessageTemplate{

            private String autoPay;

            private String courseDissolved;

            private String noEnoughMoney;

            private String courseRemind;

            private String noEnoughPeople;
        }
    }

    /**
     * 登录验证码
     */
    public static class Captcha {
        /**
         * 失效时间
         */
        private long expiration;

        public long getExpiration() {
            return expiration;
        }

        public void setExpiration(long expiration) {
            this.expiration = expiration;
        }
    }


    @Data
    public static class WxPay{
        /**
         * 设置微信公众号或者小程序等的appid
         */
        private String appId;

        /**
         * 微信支付商户号
         */
        private String mchId;

        private String mchName;

        /**
         * 子商户号
         */
        private String subMchId;

        /**
         * 微信支付商户密钥
         */
        private String mchKey;

        private String apiV3Key;
        /**
         * apiclient_cert.p12文件的绝对路径，或者如果放在项目中，请以classpath:开头指定
         */
        private String keyPath;

        private String privateKeyPath;

        private String privateCertPath;

        /**
         * 支付回调地址
         */
        private String payNotifyUrl;

        /**
         * 退款回调地址
         */
        private String refundsNotifyUrl;

    }



}
